﻿using System;

namespace KeyWordSearch.TreeParser
{
	[System.Diagnostics.DebuggerStepThrough]
	internal class Token
	{
		public Token(string textValue, TokenType attribute, int textElementIndex, int textElementLength,int index,int length)
		{
			if (textValue == null)
			{
				throw new ArgumentNullException("textValue");
			}

			if (textElementIndex < 0)
			{
				throw new ArgumentOutOfRangeException("textElementIndex");
			}

			if (textElementLength < 0)
			{
				throw new ArgumentOutOfRangeException("textElementLength");
			}

			if (index < 0)
			{
				throw new ArgumentOutOfRangeException("index");
			}

			if (length < 0)
			{
				throw new ArgumentOutOfRangeException("length");
			}

			TextValue = textValue;
			Attribute = attribute;
			TextElementIndex = textElementIndex;
			TextElementLength = textElementLength;

			this.Index = index;
			this.Length = length;
		}

		public TokenType Attribute
		{
			get;
			internal set;
		}

		public string TextValue
		{
			get;
			private set;
		}

		public int Index
		{
			get;
			private set;
		}

		public int Length
		{
			get;
			private set;
		}


		public int TextElementIndex
		{
			get;
			private set;
		}

		public int TextElementLength
		{
			get;
			private set;
		}

		public override string ToString()
		{
			return string.Format("TextValue:{0} Attribute:{1}\nTextElementStartIndex\t:{2}\tTextLength\t:{3}\nStartIndex\t\t:{4}\tLength\t\t:{5}",
				TextValue, Attribute, TextElementIndex, TextElementLength, Index, Length);
		}
	}
}
